﻿<%@page import="com.eos.system.utility.StringUtil"%>
<%@page import="com.eos.access.http.security.config.HttpSecurityConfig"%>
<%@page pageEncoding="UTF-8"%>
<%@page import="com.primeton.cap.AppUserManager"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<!-- 
  - Author(s): shitf
  - Date: 2013-03-07 15:24:13
  - Description:
-->
<head>
<title>内蒙古自治区质量技术监督局行政审批系统</title>
<%
   String contextPath=request.getContextPath();
   String url = null;
   HttpSecurityConfig securityConfig = new HttpSecurityConfig();
   boolean isOpenSecurity = securityConfig.isOpenSecurity();
   if(isOpenSecurity){
   		boolean isAllInHttps = securityConfig.isAllInHttps();
   		if(!isAllInHttps){
   			String ip = securityConfig.getHost();
   			String https_port = securityConfig.getHttps_port();
   			url = "https://" + ip + ":" + https_port + contextPath + "/coframe/auth/login/org.gocom.components.coframe.auth.login.login.flow";
   		}else{
   			url = "org.gocom.components.coframe.auth.login.login.flow"; 
   		}
   }else{
   		url = "org.gocom.components.coframe.auth.login.login.flow";
   }
 %>
 <script type="text/javascript" src="<%=contextPath%>/common/nui/nui.js"></script>
  <link href="<%=contextPath %>/coframe/auth/login/css/default.css" rel="stylesheet" type="text/css" />
	<!--必要样式-->
    <link href="<%=contextPath %>/coframe/auth/login/css/styles.css" rel="stylesheet" type="text/css" />
    <link href="<%=contextPath %>/coframe/auth/login/css/demo.css" rel="stylesheet" type="text/css" />
    <link href="<%=contextPath %>/coframe/auth/login/css/loaders.css" rel="stylesheet" type="text/css" />

</head>
<%
	String original_url=null;
	Object objAttr=request.getAttribute("original_url");
	if(objAttr != null){
		original_url=StringUtil.htmlFilter((String)objAttr);
	}
 %>
<body class="login" onLoad="checkCookie()">
<div class='login'>
	  <div class='login_title'>
	    <span>管理员登录</span>
	  </div>
	  
<div id="warpper" class="wrap">
		<div class="main">
			<div id="form1" class="login-box">
				<form method="post"	name="loginForm" onsubmit="return login();" action="<%=url%>" >
				<div class='login_fields'>
					<input id="original_url" class="nui-hidden" name="original_url" value="<%=original_url %>"/>
					<div class='login_fields__user'>
						<div class='icon'>
					        <img alt="" src='<%=contextPath %>/coframe/auth/login/img/user_icon_copy.png'>
					      </div>
						  <input class="nui-textbox" id="userId" name="userId" 
						   onenter="keyboardLogin" onvalidation="onCheckUserId"  placeholder='用户名' type='text' autocomplete="on" />
						<div class='validation'>
					        <img alt="" src='img/tick.png'>
					      </div>
					</div>
					<div class='login_fields__password'>
				      <div class='icon'>
				        <img alt="" src='<%=contextPath %>/coframe/auth/login/img/lock_icon_copy.png'>
				      </div>
					  <input name="password" id="password"  class="nui-password" vtype="minLength:6" minLengthErrorText="密码不能少于6个字符"
			                onenter="keyboardLogin" onvalidation="onCheckPassword" 
			                autocomplete="on" />
			                <div class='validation'>
					        <img alt="" src='img/tick.png'>
					      </div>
					</div>
					<div id="error" class="login-error" style="text-align:center;width:100%;display:block;height:20px;color:red;"></div>

					<div class='login_fields__submit'>
				       <input class="log" type="submit" value="登 录" />
				    </div>
				</div>
				</form>
			</div>
		</div>
	</div>
</div>
<div class='authent'>
	  <div class="loader" style="height: 44px;width: 44px;margin-left: 28px;">
        <div class="loader-inner ball-clip-rotate-multiple">
            <div></div>
            <div></div>
            <div></div>
        </div>
        </div>
	  <p>认证中...</p>
	</div>
<script src="http://www.jq22.com/jquery/jquery-1.10.2.js"></script>
<link href="<%=contextPath %>/coframe/auth/login/layui/css/layui.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" src="<%=contextPath %>/coframe/auth/login/js/jquery-ui.min.js"></script>
<script type="text/javascript" src='<%=contextPath %>/coframe/auth/login/js/stopExecutionOnTimeout.js?t=1'></script>
<script src="<%=contextPath %>/coframe/auth/login/js/Particleground.js" type="text/javascript"></script>
<script src="<%=contextPath %>/coframe/auth/login/js/Treatment.js" type="text/javascript"></script>
<script src="<%=contextPath %>/coframe/auth/login/layui/layui.js" type="text/javascript"></script>
<script type="text/javascript">
		nui.parse();
		//粒子背景特效
	    $('body').particleground({
	        dotColor: '#E8DFE8',
	        lineColor: '#133b88'
	    });
	    
	    //动画

	    $('input[name=userId]').focus(function () {

	        $('.login_fields__user').find('.icon').animate({ 'opacity': '1' }, 200);
	    });
	    $('input[name=password]').focus(function () {

	        $('.login_fields__password').find('.icon').animate({ 'opacity': '1' }, 200);
	    });
	    $('input[name=userId]').blur(function () {

	        $('.login_fields__user').find('.icon').animate({ 'opacity': '.5' }, 200);
	    });
	    $('input[name=password]').blur(function () {

	        $('.login_fields__password').find('.icon').animate({ 'opacity': '.5' }, 200);
	    });
		$('input[name=userId]').keyup(function(){
			var Len = $(this).val().length;
			if (!$(this).val() == '' && Len >= 5) {
				$('.login_fields__user').find('.validation').animate({
	                'opacity': '1',
	                'right': '30'
	            }, 200);
			}else{
				$('.login_fields__user').find('.validation').animate({
	                'opacity': '0',
	                'right': '20'
	            }, 200);
			}
		})
		$('input[name=password]').keyup(function(){
			var Len = $(this).val().length;
			if (!$(this).val() == '' && Len >= 5) {
				$('.login_fields__password').find('.validation').animate({
	                'opacity': '1',
	                'right': '30'
	            }, 200);
			}else{
				$('.login_fields__password').find('.validation').animate({
	                'opacity': '0',
	                'right': '20'
	            }, 200);
			}
		})

		function getCookie(c_name) //根据分隔符每个变量的值
		{
			if (document.cookie.length > 0) {
			c_start = document.cookie.indexOf(c_name + "=")
			if (c_start != -1) { 
			c_start = c_start + c_name.length + 1;
			c_end = document.cookie.indexOf("^",c_start);
		if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		} 
		}
			return "";
		} 
		function setCookie(c_name, n_value, p_name, p_value, expiredays) //设置cookie
		{
			var exdate = new Date();
			exdate.setDate(exdate.getDate() + expiredays);
			document.cookie = c_name + "=" + escape(n_value) + "^" + p_name + "=" + escape(p_value) + ((expiredays == null) ? "" : "^;expires=" + exdate.toGMTString());
			console.log(document.cookie);
		}
		
		function checkCookie() //检测cookie是否存在，如果存在则直接读取，否则创建新的cookie
		{
		
			
			var username = getCookie('username');  
			var password = getCookie('password');
			if (username != null && username != "" && password != null && password != "")
		{
			//setCookie('username', username, 'password', password, 365);
			nui.get("userId").setValue(username);
			nui.get("password").setValue(password);
		}
		}
		
		function cleanCookie (c_name, p_name) { //使cookie过期
			document.cookie = c_name + "=" + ";" + p_name + "=" + ";expires=Thu, 01-Jan-70 00:00:01 GMT";
		}
</script>
<script type="text/javascript">
     if(window.top!=window){
		window.top.location = window.location;
	 }
     nui.parse();
  
     var form = new nui.Form("#form1");
     
     nui.get("userId").focus();
     
     function onCheckUserId(e){
       if (e.isValid) {
         if(e.value==""){
          	ErroAlert('用户名不能为空');

         }
       }
     }
     
     function onCheckPassword(e){
       if (e.isValid) {
         if(e.value==""){
         	ErroAlert('密码不能为空');
         }
       }
     }
     <% 
     	Object result = request.getAttribute("result");
     	String userName = (String)request.getAttribute("userId");
     	if (userName==null)userName="";
     	String password = (String)request.getAttribute("password");
     	if (password==null)password="";
     	if(result != null){
     		Integer resultCode = (Integer)result;
     		 if(resultCode == 0){
		     	out.println("showError('密码错误！')");
		     }else if(resultCode == -1){
		     	out.println("showError('用户不存在！')");
		     }else if(resultCode == -2){
		     	out.println("showError('用户无权限登录，请联系系统管理员！')");
		     }else if(resultCode == 3){
		     	out.println("showError('用户已过期！')");
		     }else if(resultCode == 4){
		     	out.println("showError('用户未到开始使用时间！')");
		     }else if(resultCode == 5){
		     	out.println("showError('密码已过期！')");
		     }else if(resultCode == -3){
      			out.println("showError('查询用户信息失败，请联系系统管理员检查数据库连接！')");
     		 }else{
      			out.println("showError('未知的异常，请联系系统管理员！')");
     		 }
     	}
	  %>
      function showError(msg){
      $('#error').html(msg)
	      //layui.use('layer', function () {
	       					
	      //	ErroAlert(msg)
	     // })

      }
      
      //获取键盘 Enter 键事件并响应登录
     function keyboardLogin(e){
       login();
     }
     function login(){
     	var form = new nui.Form("#form1");
        form.validate();
        if (form.isValid() == false) 
        	return false;
        
		if(nui.get("isRember").getValue() == "true"){
		setCookie('username', nui.get("userId").getValue(), 'password', nui.get("password").getValue(), 365);
		}        document.loginForm.submit();
     }
     $(function(){
 		var validateResult = "<%=result %>";
 		nui.get("userId").setValue("<%=userName %>");
 		nui.get("password").setValue("<%=password %>");
 	 });
</script>
 </body>
  <%
 	request.getSession().invalidate();
 	Cookie[] cookies = request.getCookies();
 	if(cookies != null){
 		for(int i=0;i<cookies.length;i++){
 			if(StringUtil.equals("jsessioinid", cookies[i].getName())){
 				cookies[i].setMaxAge(0);
 			}
 		}
 	
 	}
  %>
</html>
